import cv2 as cv
import argparse
from center_detect_methods.center_detect import (
    ConvenCentroid,
    WeightedCentroid,
    HeissanMethod,
    GaussFitMethod,
)
from corner_detect_methods.corner_detect import (
    KitchenRosenfeldMethod,
    HarrisMethod,
    OpencvMethod,
)
from corner_detect_methods.corner_detect import HeissanMethod as HeissanCornerMethod
import os


def arg_parse():
    args_parser = argparse.ArgumentParser()
    args_parser.add_argument(
        "--input", "-i", type=str, default="./src_fig/detection/center_light_field.bmp"
    )
    args_parser.add_argument(
        "--method",
        type=str,
        help="This kind of argument can be chosen from these values: C, WC, H, G, respectively standing for centriod method, weighted centriod method, Heissan matrix method, Gaussian fitting method. And if choose corner detection task, this argument can be chosen from these values: KR, HA, O, HE, respectively standing for KitchenRosenfeld method, Harris method, Opencv method, Heissan matrix method.",
    )
    args_parser.add_argument("--output", "-o", type=str, default="./output")
    args_parser.add_argument(
        "--ksize", type=int, default=9, help="size for gaussian convolution kernel"
    )
    args_parser.add_argument(
        "--sigma", type=float, default=1.5, help="sigma for gaussian convolution kernel"
    )
    args_parser.add_argument(
        "--wsize",
        type=int,
        default=3,
        help="size for harris corner detection window and other blocksize",
    )
    args_parser.add_argument(
        "--interp",
        type=str,
        default="none",
        help="This kind of argument can be chosen from these values: gauss_fit, cross_line, opencv, taylor, respectively standing for gauss fitting method, cross line method, opencv method, taylor method.",
    )
    args_parser.add_argument(
        "--filter",
        type=str,
        default="none",
        help="This kind of argument can be chosen from these values: vicinity, none, respectively standing for vicinity filter method, none filter method.",
    )
    args_parser.add_argument(
        "--thres", type=float, default=5e-2, help="threshold for filter method"
    )
    args_parser.add_argument(
        "--task",
        type=str,
        help="This kind of argument can be chosen from these values: center, corner, respectively standing for center detection task and corner detection task.",
    )
    args_parser.add_argument(
        "--zoom", action="store_true", help="zoom the output image"
    )
    args = args_parser.parse_args()
    return args


if __name__ == "__main__":
    args = arg_parse()
    guangban = cv.imread(args.input, cv.IMREAD_GRAYSCALE)
    if not os.path.exists(args.output):
        os.mkdir(args.output)
    methods = {
        "center": {
            "C": ConvenCentroid,
            "WC": WeightedCentroid,
            "H": HeissanMethod,
            "G": GaussFitMethod,
        },
        "corner": {
            "KR": KitchenRosenfeldMethod,
            "HA": HarrisMethod,
            "O": OpencvMethod,
            "HE": HeissanCornerMethod,
        },
    }
    methods[args.task][args.method](guangban).run(
        os.path.join(args.output, args.task), **args.__dict__
    )
